Skip to content

feat(util.dataset): add simulate_if_needed one-line auto-simulate helper - #670

Merged
Jammy2211 merged 1 commit into
mainfrom
claude/pyautoarray-simulate-helper-yuqd16
Nov 1, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
claude/pyautoarray-simulate-helper-yuqd16

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Phase 1 of #669.

Summary

  • Adds aa.util.dataset.simulate_if_needed(dataset_path, simulator) to autoarray/util/dataset_util.py. When should_simulate(str(dataset_path)) is True it runs subprocess.run([sys.executable, str(simulator)], check=True). It returns whether the simulator ran.
  • Uses a subprocess on purpose, not runpy, so the simulator's JAX/matplotlib/module state cannot leak into the calling script. check=True means a failing simulator raises instead of letting the caller load a missing dataset.
  • Accepts str or Path for both arguments.
  • The usage example in the should_simulate docstring now points at the helper.

This lets workspaces replace the 8-line block:

if al.util.dataset.should_simulate(str(dataset_path)):
    import subprocess
    import sys

    subprocess.run([sys.executable, "scripts/simulator/lens_x2.py"], check=True)

with:

al.util.dataset.simulate_if_needed(dataset_path, simulator="scripts/simulator/lens_x2.py")

The workspace sweep (phase 3) waits for a release. The companion PyAutoHands PR makes check_dataset_allowlist recognise the new call, so swept scripts stay guarded.

Testing

  • New tests in test_autoarray/util/test_dataset_util.py mock subprocess.run. They check that it is called exactly once with [sys.executable, str(simulator)] and check=True when should_simulate is True, that it is not called when False, that both str and Path arguments work, and that a missing dataset triggers the run.
  • pytest test_autoarray/util: 148 passed.

al.util.dataset / ag.util.dataset should expose the helper automatically, because they re-export this module (the workspaces already call al.util.dataset.should_simulate). That wasn't checked against PyAutoGalaxy/PyAutoLens in this session.

Merge mode: human /prm.


Generated by Claude Code

Adds aa.util.dataset.simulate_if_needed(dataset_path, simulator), which
runs the simulator script in a subprocess (sys.executable, check=True)
only when should_simulate(dataset_path) is True. Subprocess isolation is
kept deliberately (not runpy) so simulator JAX/matplotlib state cannot
leak into the caller. Accepts str or Path for both args and returns
whether the simulator ran.

The should_simulate docstring's usage example now points at the helper.
Tests mock subprocess.run for both branches and both arg types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016nhQ8NyQo2s3YUk8eUrrB3
@Jammy2211
Jammy2211 merged commit c7da8b0 into main Nov 1, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the claude/pyautoarray-simulate-helper-yuqd16 branch November 1, 2026 15:59
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Nov 1, 2026 — with Claude
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants